﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;

namespace aio_exe
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            var count= Screen.AllScreens.Count();
            
            //程序运行的目录
            var appPath = Directory.GetCurrentDirectory()+"\\";

            //如果配置文件不存在就创建一份
            if (!File.Exists(appPath + "aio.xml"))
            {

                using (StreamWriter sw = new StreamWriter(appPath + "aio.xml"))
                {

                    String val = @"<?xml version=""1.0"" encoding=""UTF-8""?><index> 0 | www.qq.com </index> ";
                    sw.WriteLine(val);
                   
                }
               
            }

            //解析XML配置
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(appPath + "aio.xml");//读取xml文件
            XmlNode xn = xmlDoc.SelectSingleNode("index");

            string[] configArray = xn.InnerText.Split('|');
          
            int index = Convert.ToInt32(configArray[0]);
            String url = configArray[1];

            webBrowser.Navigate(url);
        
            showOnMonitor(index);//index=1

            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
        }

     



        private void showOnMonitor(int showOnMonitor)
        {
            Screen[] sc;
            sc = Screen.AllScreens;
            if (showOnMonitor >= sc.Length)
            {
                showOnMonitor = 0;
            }


            this.StartPosition = FormStartPosition.Manual;
            this.Location = new Point(sc[showOnMonitor].Bounds.Left, sc[showOnMonitor].Bounds.Top);
            // If you intend the form to be maximized, change it to normal then maximized.
            this.WindowState = FormWindowState.Normal;
            this.WindowState = FormWindowState.Maximized;
        }

    }
}
